'use strict';
/**
 * Created by deng on 16-3-4.
 */

angular.module('metalabPartnerApp').controller('OfficerVerify', ['$rootScope', '$scope', '$state', '$uibModalInstance', 'MetaResources', 'MetaRemind', 'MetaConstants',
    function ($rootScope, $scope, $state, $uibModalInstance, MetaResources, MetaRemind, MetaConstants) {

        //七牛配置
        $scope.config = {
            uptokenUrl: CONFIG.qnuploader.uptokenUrl,
            domain: CONFIG.qnuploader.domain,
            maxSize: CONFIG.qnuploader.maxSize
        };

        $scope.demandFields = MetaConstants.demandFields;

        $scope.provinces = MetaConstants.provinces;
        $scope.cities = MetaConstants.cities;

        $scope.partnerInfo = {
            areas: [],

            camp: [],

            organization: null,

            department: null,

            post: null,

            projectExperience: null,

            resume: null,

            score: null
        };


        MetaResources.user.get({'id': '_self'}, function (data) {
            $scope.rawInfo = data.partnerInfo;
            $scope.partnerInfo = $scope.rawInfo ? angular.copy($scope.rawInfo) : $scope.partnerInfo;
        }, function (error) {
            MetaRemind.error(error);
        });

        //更新Officer
        $scope.updateOfficer = function (valid) {
            if (valid) {
                //更新USER信息
                MetaResources.user.update({'id': '_self'}, {
                    partnerInfo: $scope.partnerInfo,
                }, function (data) {
                    //$rootScope.clearOfficerVerifyModal();
                    MetaRemind.success('保存成功');
                    $uibModalInstance.close();
                    $state.go('.', {officer: undefined}, {notify: false});
                });
                //成功后
            } else {
                $scope.clicked = true;
                MetaRemind.error('请完整填写表单内容!');
            }
        };

        $scope.reset = function () {
            $scope.partnerInfo = angular.copy($scope.rawInfo);
        };

        //$rootScope.$watch('USER', function () {
        //    $scope.partnerInfo = angular.copy($rootScope.USER);
        //}, true);
    }]);
